package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.AddAfterServiceInfoBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.AddAfterServiceInfoCall;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.afterserviceinfo;
import com.ymttest.database.model.afterserviceinfoExample;
import com.ymttest.database.sqlwapper.godmch.afterserviceinfoWapper;
import com.ymttest.utils.TestDataManager;
/**
*新增售后信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddAfterServiceInfo{
	private static AddAfterServiceInfoBean bean;
	private static AddAfterServiceInfoCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增售后信息");
	}

	@Before
	public void caseUp() {
		bean=new AddAfterServiceInfoBean();
		call=new AddAfterServiceInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
    private void  check_verify() throws InterruptedException, JSONException
    {
    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
    	Logger.verifyEquals(true, call.getSuccess(), "验证Success");
    	
    	afterserviceinfoWapper infoWapper=new afterserviceinfoWapper();
		afterserviceinfoExample Example=new afterserviceinfoExample();
		afterserviceinfoExample.Criteria criteria = Example.createCriteria();
		criteria.andMchIdEqualTo(bean.getMchId());
		if(bean.getRemark()!=null && bean.getRemark()!="")
		 criteria.andRemarkEqualTo(bean.getRemark());
		if(bean.getMobile()!=null && bean.getMobile()!="")
		 criteria.andMobileEqualTo(bean.getMobile());
		if(bean.getWeChat()!=null && bean.getWeChat()!="")
		  criteria.andWeChatEqualTo(bean.getWeChat());
		if(bean.getAddress()!=null && bean.getAddress()!="")
		   criteria.andAddressEqualTo(bean.getAddress());
		List<afterserviceinfo> infos=infoWapper.selectByExample(Example);
		Logger.verifyEquals(1, infos.size(), "验证数据库有条新增数据");
    }
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_001() {
		Logger.start(true,"正例-新增售后信息-商户是渠道");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_002() {
		Logger.start(true,"正例-新增售后信息-商户是代理+渠道");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			
			bean.setMchId(mchId_agent);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_002_1() {
		Logger.start(true,"正例-新增售后信息-商户是代理");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			bean.setMchId(mchId_agent);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_003() {
		Logger.start(true,"反例-新增售后信息-mchId为空");
		try {
			
			//bean.setMchId(mchId_agent);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_003_1() {
		Logger.start(true,"反例-新增售后信息-ParentMchId为空");
		try {
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			bean.setMchId(mchId_agent);
		//	bean.setParentMchId(parentMchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_004() {
		Logger.start(true,"反例-新增售后信息-remark为空");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			bean.setParentMchId(mchId);
			//bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			
			check_verify();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_005() {
		Logger.start(true,"反例-新增售后信息-mobile为空");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			//bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			
			check_verify();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_006() {
		Logger.start(true,"反例-新增售后信息-address为空");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			//bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			
			check_verify();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAfterServiceInfo_007() {
		Logger.start(true,"正例-新增售后信息-weChat为空-不限制");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			bean.setParentMchId(mchId);
			bean.setRemark("备注_"+TestDataManager.getRandomNum(4));
			bean.setMobile(TestDataManager.getPhoneNum());
			//bean.setWeChat("微信号_"+TestDataManager.getRandomNum(4));
			bean.setAddress("地址_"+TestDataManager.getRandomNum(4));
			call.setData(bean);
			call.callService();	
			
			this.check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}